<template>
  <div id="login">
    <div class="logo">
      <div style="text-align:center;margin-top: 25px;">
        <img src="./theme/images/logo.svg" style="width:200px;"/>
      </div>
    </div>
    <div class="content">
      <div>
        <el-form ref="model" :model="model" v-loading="loading" element-loading-text="正在登录，请稍等">

          <el-form-item prop="id" :rules="[{ required: true, message: '请输入登录账号'}]">
            <el-input type="text" v-model="model.id" size="small" placeholder="请输入登录账号"
                      prefix-icon="el-icon-user-solid" style="margin-top: 10px;"
                      clearable></el-input>
          </el-form-item>
          <el-form-item prop="pwd" :rules="[{ required: true, message: '请输入用户密码'}]">
            <el-input type="password" v-model="model.pwd" size="small" placeholder="请输入登录密码"
                      prefix-icon="el-icon-s-goods" style="margin-top: 25px;" clearable></el-input>
          </el-form-item>
          <template v-if="model.msg!=''">
            <span style="color:red;line-height:30px;padding-left:5px;">{{ model.msg }}</span>
          </template>
          <el-form-item>
            <el-button type="primary" @click="submit" size="small" style="width: 100%; margin-top: 40px; line-height: 22px;font-size:16px;margin-bottom: 10px;">绑&nbsp;定
            </el-button>
          </el-form-item>
        </el-form>
        <elm-dialog ref="dialog"></elm-dialog>
      </div>
    </div>
    <div class="copyright"></div>
  </div>
</template>
<script>
import settle_out_edit from "../business/bms/settle_out_edit.vue";

export default {
  extends: elmVueBase,
  data() {
    return {
      loading: false,
      model: {id: '', pwd: '', msg: ''},
    }
  },
  async mounted() {
    console.log(111111111111111111111)
    let res = localStorage.getItem("weixinLoginInfo")
    console.log('存储结果：',res)
    if (res) {
       res = JSON.parse(res)
       this.login(res)
    }
  },
  methods: {
    async submit() {
      await this.$refs["model"].validate();
      this.loading = true;
       let res = await elm.post("/system/login/AuthLogin", {
          id: this.model.id,
          pwd: this.model.pwd,
          url: elm.query("url")
        });
        localStorage.setItem("weixinLoginInfo", JSON.stringify(res));
      console.log('登录：', res);
      this.login(res)
      this.loading = false;
    },
    async login(res) {
      if (res.success == true) {
        elm.info.token = res.token;
        const parts = this.model.id.split(".");
        elm.info.tenant =parts[parts.length - 1];
        if (res.authpage == "pass_eidt_1") {
          this.loading = false;
          elm.dialog.open(this, "/v/system/pass_eidt", "您的密码强度不够，请修改密码后重新登录！", 500, 400, {id: this.model.id});
          return;
        }
        else  if (res.authpage == "pass_eidt") {
          this.loading = false;
          elm.dialog.open(this, "/v/system/pass_eidt", "使用初始化密码登录后，需重设密码后重新登录！", 500, 400, {id: this.model.id});
          return;
        }
        elm.info.system = res.system;
        elm.info.menu = res.menu;
        elm.info.user = res.user;
        elm.info.org = res.org;
        elm.info.role = res.role;
        location.href = elm.settings.routefix + elm.info.system.path;
        //记录日志
        let oper_log = {};
        oper_log.oper_type = "0"; //PC
        oper_log.user_name = this.model.id;
        oper_log.nick_name = res.user.name;
        oper_log.menu_title = "/system/login/AuthLogin";
        oper_log.oper_time = new Date().toLocaleString();
        oper_log.msg = "登录";
        await elm.post('/system/login/log/Upsert', oper_log);
      } else if (res.success == false || res.status == 401) {
        this.model.msg = "用户名或密码错误。";
      } else {
        this.model.msg = "登录失败，请稍后重试。";
      }
    }
  }
};
</script>

<style scoped>
@import url('theme/login.css');
.login .el-form-item {
  border: 0px solid #EBEEF5 !important;
}
#login
{
  background-color: rgba(255,255,255,0.8);
  border-radius: 12px;
  box-shadow: 0 0px 15px 0 rgba(0,39,87,0.2) ;
  width: 370px;
}
#login .content {
  background: rgba(125,218,255,0.0);
  width: 350px;
}
.el-button {
  background: rgb(3,138,255) !important;
  color: rgb(255,255,255) !important;
  border: 0px solid #EBEEF5 !important;
}

.el-button:hover {
  background: rgba(3,138,255,0.8) !important;
  color: rgb(255,255,255) !important;
  border: 0px solid #EBEEF5 !important;
}

.el-form {
  border: 0px solid #EBEEF5;
}

</style>